package br.com.vendas.menu;

import java.io.IOException;

import br.com.main.Main;
import br.com.vendas.exception.ArqException;

public class ItemVoltar extends ItemMenu {

	@Override
	public int getId() {
		return 0;
	}

	@Override
	public String getNome() {
		return (Main.MENUS.size() <= 1) ? "Finalizar" : "Voltar";
	}

	@Override
	protected void processamento() throws IOException, ArqException {
		if( Main.MENUS != null && Main.MENUS.size() > 1 ) {
			// tira o ultimo
			Main.MENUS.remove( Main.MENUS.size()-1 );
			
			// guarda o que deve processar
			Menu menu = Main.MENUS.get( Main.MENUS.size()-1 );
			
			// retira, pois sera inserido novamente
			Main.MENUS.remove( Main.MENUS.size()-1 );
			
			// processa
			menu.processar();
		} else {
			System.out.println("FIM");
		}
	}
	
}
